<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>信息系统后台管理系统</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src='js/jquery.min.js' ></script>
<script type="text/javascript" src='js/jquery.base64.js' ></script>
<script type="text/javascript" src='js/jquery.cookie.js' ></script>
<script src="js/cloud.js" type="text/javascript"></script>
<script language="javascript">
if(self != top){
	top.location.href="<%=request.getContextPath()%>/login.jsp";
}
document.onkeydown=function(event){
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode==13){
		login();
	}        
}; 
function login(){
	var user = $('#userNo').val();
	var pwd = $('#pwd').val();
	if(user==null||user==''){
		alert("用户名不能为空!");
		return;
	}
	
	if(pwd==null||pwd==''){
		alert("密码不能为空!");
		return;
	}	
	
	setCookie();
	
	$.ajax({
	    url: '<%=request.getContextPath()%>/loginAction.action?method=login',
	    type: 'post',
	    data:{
			user:user,
			password:pwd
		},
		dataType: 'json',
	    error: function(){
	        alert('加载失败!');
	    },
	    success: function(data){	
			if(data.result!='true'){
				alert(data.result);
			}else{
				self.location= "<%=request.getContextPath()%>/main.jsp";
			}	    
		}
	});
}

function setCookie(){ //设置cookie
	var loginCode = $("#userNo").val(); //获取用户名信息
	var pwd = $("#pwd").val(); //获取登陆密码信息
	var checked = $("[name='checkbox']:checked");//获取“是否记住密码”复选框
	if(checked&&checked.length > 0){ //判断是否选中了“记住密码”复选框
		$.cookie("userNo",loginCode);//调用jquery.cookie.js中的方法设置cookie中的用户名
		$.cookie("pwd",$.base64.encode(pwd));//调用jquery.cookie.js中的方法设置cookie中的登陆密码，并使用base64（jquery.base64.js）进行加密
		$.cookie("checkbox",true);
	}else{
		$.cookie("userNo",loginCode);//调用jquery.cookie.js中的方法设置cookie中的用户名
		$.cookie("pwd","");
		$.cookie("checkbox",false);
	}
} 

function getCookie(){ //获取cookie
 	var loginCode = $.cookie("userNo"); //获取cookie中的用户名
 	var pwd =  $.cookie("pwd"); //获取cookie中的登陆密码
 	var checkbox =  $.cookie("checkbox"); //获取cookie中的登陆密码 	
 	if(checkbox==true||checkbox=='true'){//密码存在的话把“记住用户名和密码”复选框勾选住
 		$("[name='checkbox']").attr("checked","true");
 	}
 	
 	if(loginCode!=null&&loginCode!=""){//用户名存在的话把用户名填充到用户名文本框
 		$("#userNo").val(loginCode);
 	}
 	
 	if(pwd!=null&&pwd!=''){//密码存在的话把密码填充到密码文本框
 		$("#pwd").val($.base64.decode(pwd));
 	}else{
 		$("#pwd").val("");
 	}
}

$(function(){
    $('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
	$(window).resize(function(){  
   	    $('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
    });
	getCookie();
});  
</script>
</head>
<body
	style="background-color: #1c77ac; background-image: url(images/light.png); background-repeat: no-repeat; background-position: center top; overflow: hidden;">
	<div id="mainBody">
		<div id="cloud1" class="cloud"></div>
		<div id="cloud2" class="cloud"></div>
	</div>
	<div class="logintop">
		<span>信息系统后台管理系统</span>
		<ul>
			<li><a href="web/index.jsp">回首页</a></li>
			<!--   <li><a href="#">帮助</a></li>
    <li><a href="#">关于</a></li> -->
		</ul>
	</div>
	<div class="loginbody">
		<span class="systemlogo"></span>
		<div class="loginbox">
			<ul>
				<li><input name="userNo" type="text" class="loginuser" value="" id="userNo"
					onclick="JavaScript:this.value=''" /></li>
				<li><input name="pwd" type="password" class="loginpwd" value="" id="pwd"
					onclick="JavaScript:this.value=''" /></li>
				<li><input name="" type="button" class="loginbtn" value="登陆" onclick="javascript:login()" /><label>
					<input id="checkbox" name="checkbox" type="checkbox" value="" />记住密码</label>
				</li>
			</ul>
		</div>
	</div>
	<div class="loginbm"></div>
</body>
</html>
